<?php

/**
 * 存存管理 
 *
 */ 

class inventoryAction extends backendAction
{
    public function _initialize() {
        parent::_initialize();
        $this->_cate_mod = D('region');
    }
    
    public function _before_index() {  
        $big_menu = array(
            'title' => L('add_inventory'),
            'iframe' => U(MODULE_NAME.'/add'),
            'id' => 'add',
            'width' => '500',
            'height' => '200'
        );
        $this->assign('big_menu', $big_menu);        
        $this->readyData();     
        $this->list_relation = true;
    }
    
   
    
    public function _before_add(){
        $this->readyData();   
    }
    public function _before_edit(){
        $this->readyData();   
    }
    
    private function readyData(){
        
        //地市下拉框
        $tree = new Tree();
        $result = M('region')->select();
        $array = array();
        foreach($result as $r) {
            $r['selected'] = $r['id'] == $_REQUEST['regionId'] ? 'selected' : '';
            $array[] = $r;
        }
        $str  = "<option value='\$id' \$selected>\$spacer \$name</option>";
        $tree->init($array);
        $regionMenus = $tree->get_tree(0, $str);
        $this->assign('regionMenus', $regionMenus);        
        
        //品牌列表
        $brandList = F('brand_list');
        if(empty($bandList)){
            $brandList = D('brand')->cate_cache();
        }
        $this->assign('brandList',$brandList);
    }
    /**
     * 获取请求参数生成条件数组
     */
    protected function _search() {
        $map = array();      
        ($storeId = $this->_request('storeId', 'intval')) && $map['storeId'] = $storeId;
        ($brandId = $this->_request('brandId', 'intval')) && $map['brandId'] = $brandId;        
        $regionId = $this->_request('regionId', 'intval');       
        if ($regionId) {
            $id_arr = $this->_cate_mod->get_child_ids($regionId, true);
            $map['regionId'] = array('IN', $id_arr);
        }
        $this->assign('search', array(
            'storeId'=>$storeId,
            'regionId' => $regionId,
            'brandId'=>$brandId,
            'channel'  => $channel,            
        ));
        return $map;
    
    }
}

?>